
package com.sm.shoplook.service.suit.impl;

import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sm.shoplook.constant.ResultMessage;
import com.sm.shoplook.dao.mapper.suit.SuitCommentMapper;
import com.sm.shoplook.service.suit.SuitCommentService;
import com.sm.shoplook.vo.base.ApiException;
import com.sm.shoplook.vo.base.ApiResult;
import com.sm.shoplook.vo.suit.back.req.SuitCommentPageReqVo;
import com.sm.shoplook.vo.suit.back.resp.SuitCommentRespVo;

@Service
public class SuitCommentServiceImpl implements SuitCommentService {

	private static final Logger LOGGER = LoggerFactory.getLogger(SuitCommentServiceImpl.class);
	@Autowired
	private SuitCommentMapper suitCommentMapper;

	@Override
	public ApiResult<PageInfo<SuitCommentRespVo>> selectSuitCommentListPage(SuitCommentPageReqVo suitCommentPageReqVo) {
		PageHelper.startPage(suitCommentPageReqVo.getOffset(), suitCommentPageReqVo.getPageSize());
		List<SuitCommentRespVo> suitRespVos = suitCommentMapper.selectSuitCommentListPage(suitCommentPageReqVo);
		return new ApiResult<>(ResultMessage.RESULT_SUCCESS_1, new PageInfo<>(suitRespVos));
	}

	@Override
	public ApiResult<SuitCommentRespVo> selectSuitCommentById(Integer id) {
        SuitCommentPageReqVo suitSearchReqVo = new SuitCommentPageReqVo();
		suitSearchReqVo.setId(id);
		List<SuitCommentRespVo> suitPageRespVos = suitCommentMapper.selectSuitCommentListPage(suitSearchReqVo);
		if (CollectionUtils.isEmpty(suitPageRespVos)) {
			return new ApiResult<>(ResultMessage.SUIT_COMMENT_NOT_EXISTS);
		}
		return new ApiResult<>(ResultMessage.RESULT_SUCCESS_1, suitPageRespVos.get(0));
	}

	@Override
	public ApiResult<Integer> batchDelete(String[] ids) throws ApiException {
		int i = suitCommentMapper.batchDelete(ids);
		if (i > 0) {
			return new ApiResult<>(ResultMessage.RESULT_SUCCESS_1);
		}
		throw new ApiException();
	}
}
